﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;
using System.Collections.Concurrent;
using Newtonsoft.Json;
using YetAnotherChat.TcpServer;
using YetAnotherChat.TcpConsole.Model;
using YetAnotherChat.UserManagement.Models;
using YetAnotherChat.ChatCore.Models;

namespace YetAnotherChat.TcpConsole
{
    class Program
    {
        private static MessageBroadcaster _messageBroadcaster;

        /// <summary>
        /// Initialize the application and start the Alchemy Websockets server
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Initialize the server on port 81, accept any IPs, and bind events.
            var aServer = new WebSocketServer(81, IPAddress.Any)
            {
                TimeOut = new TimeSpan(0, 5, 0)
            };
            var messageBroadcaster = new MessageBroadcaster(aServer);

            aServer.Start();

            // Accept commands on the console and keep it alive
            var command = string.Empty;
            while (command != "exit")
            {
                command = Console.ReadLine();
            }

            aServer.Stop();
        }
       
    }

    /// <summary>
    /// Defines the type of response to send back to the client for parsing logic
    /// </summary>
    public enum ResponseType
    {
        Connection = 0,
        Disconnect = 1,
        Message = 2,
        NameChange = 3,
        UserCount = 4,
        Error = 255
    }

    /// <summary>
    /// Defines the response object to send back to the client
    /// </summary>
    public class Response
    {
        public ResponseType Type { get; set; }
        public object Data { get; set; }
        public bool FromAjaxWeb { get; set; }
    }


    /// <summary>
    /// Defines a type of command that the client sends to the server
    /// </summary>
    public enum CommandType
    {
        Register = 0,
        Message,
        NameChange
    }
}
